let {GetUserInfo,GetOpenid}=require("../../api/api");
// pages/index/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // bannerData:[
    //   "../../image/banner/banner1.jpg",
    //   "../../image/banner/banner2.jpg",
    //   "../../image/banner/banner3.jpg",
    //   "../../image/banner/banner4.jpg",
    //   "../../image/banner/banner5.jpg",
    //   "../../image/banner/banner6.jpg",
    //   "../../image/banner/banner7.jpg",
    //   "../../image/banner/banner8.jpg",
    //   "../../image/banner/banner9.jpg",
    //   "../../image/banner/banner10.jpg",
    // ],
    bannerData:[
      "https://wftpay.ssgddsj.com/b30Img/banner1.jpg",
      "https://wftpay.ssgddsj.com/b30Img/banner2.jpg",
      "https://wftpay.ssgddsj.com/b30Img/banner3.jpg",
      "https://wftpay.ssgddsj.com/b30Img/banner4.jpg",
      "https://wftpay.ssgddsj.com/b30Img/banner5.jpg",
      "https://wftpay.ssgddsj.com/b30Img/banner6.jpg",
      "https://wftpay.ssgddsj.com/b30Img/banner7.jpg",
      "https://wftpay.ssgddsj.com/b30Img/banner8.jpg",
      "https://wftpay.ssgddsj.com/b30Img/banner9.jpg",
      "https://wftpay.ssgddsj.com/b30Img/banner10.jpg",
    ],
    indicatorDots: false,
    autoplay: false,
    interval: 4000,
    duration: 500,
    circular: false,
    current:0,
    leftFalg:true,
    rightFalg:true
  },
  bannerChnage(e){
    this.setData({
      current:e.detail.current
    })
  },
  btnLeft(){
    if (this.data.current==0) {
      return;
    }
    if (this.data.leftFalg) {
      this.setData({
        current:this.data.current - 1,
        leftFalg:false
      })
      setTimeout(() => {
        this.setData({
          leftFalg:true
        })
      }, 500);
    }

  },
  btnRight(){
    if (this.data.current==9) {
      return;
    }
    if (this.data.rightFalg) {
      this.setData({
        current:this.data.current + 1,
        rightFalg:false
      })
      setTimeout(() => {
        this.setData({
          rightFalg:true
        })
      }, 500);
    }

  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

    wx.login({
      success: res => {
        let code=res.code;
       GetOpenid(code,(e)=>{
          let openid=e.data.openid;
          // let session_key=e.data.session_key;
          wx.setStorageSync("openid",openid);
          // wx.setStorageSync("session_key",session_key);
            GetUserInfo(openid,(e)=>{
              var data = e.data;
              if(data){
                var phone_num = data.phone_num;
                  if(phone_num!=''){//不为空 根据电话号码获取用户食谱数据
                    wx.setStorageSync("phone_num", phone_num);
                  }else{

                    wx.showModal({
                      title: '登录才能获取专属饮食方案',
                      content: '是否跳转到登录授权页面',
                      success (res) {
                        if (res.confirm) {
                          // console.log('用户点击确定');
                          wx.reLaunch({
                            url: '../login/login',
                          })
                        } else if (res.cancel) {
                          // console.log('用户点击取消')
                        }
                      }
                    })
                 
                  }
              }
              else{ 
                wx.showModal({
                  title: '登录才能获取专属饮食方案',
                  content: '是否跳转到登录授权页面',
                  success (res) {
                    if (res.confirm) {
                      // console.log('用户点击确定');
                      wx.reLaunch({
                        url: '../login/login',
                      })
                    } else if (res.cancel) {
                      // console.log('用户点击取消')
                    }
                  }
                })
           
              }
            })
       })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})